"""
词云图
"""

from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba


font_path = r'C:\WINDOWS\FONTS\DENGL.TTF'
sentence = '郭靖和哀牢山三十六剑。'

# 获取空格分割的文本
space_sentence = ' '.join(jieba.cut(sentence))
# 创建WordCloud对象
# wc = WordCloud(font_path=font_path)
wc = WordCloud(
    font_path=font_path,
    width=800, height=600,
    # 透明背景色
    mode='RGBA', background_color=None,
)
# 通过文本生成词云
wc.generate(space_sentence)
# 保存到本地
wc.to_file('wordcloud1.png')

# 将词云绘制到matplotlib图像上
plt.imshow(wc)
# 不显示坐标轴
plt.axis('off')
plt.show()

